﻿
	using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Linq.Dynamic;
    using System.Text;
    using System.Threading.Tasks;
    using Abp;
    using Abp.Application.Services.Dto;
    using Abp.Authorization;
    using Abp.AutoMapper;
    using Abp.Configuration;
    using Abp.Domain.Repositories;
    using Abp.Extensions;
    using Abp.Linq.Extensions;
    using KDS.Mes.Mes.PlanDetails.Dtos;
using KDS.Mes.DataExporting.Excel.EpPlus;
using Abp.Timing.Timezone;
using Abp.Runtime.Session;
using KDS.Mes.Dto;

namespace KDS.Mes.Mes.PlanDetails
{
    /// <summary>
    /// 详细计划信息的导出EXCEL功能的实现
    /// </summary>
    public class PlanDetailListExcelExporter : EpPlusExcelExporterBase, IPlanDetailListExcelExporter
    {
     
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;


        /// <summary>
        /// 构造方法
        /// </summary>
        public PlanDetailListExcelExporter(ITimeZoneConverter timeZoneConverter,     IAbpSession abpSession)
        {
                       _timeZoneConverter = timeZoneConverter;    
                     _abpSession = abpSession;
        }

    

         /// <summary>
        /// 导出详细计划信息到EXCEL文件
        /// <param name="planDetailListDtos">导出信息的DTO</param>
        /// </summary>
    public    FileDto ExportPlanDetailToFile(List<PlanDetailListDto> planDetailListDtos){


var file=CreateExcelPackage("planDetailList.xlsx",excelPackage=>{

var sheet=excelPackage.Workbook.Worksheets.Add(L("PlanDetail"));
                    sheet.OutLineApplyStyle = true;

                    AddHeader(
                        sheet,
                          L("PlanId"),  
     L("SeatPositionId"),  
     L("SeatID"),  
     L("SeatSeq"),  
     L("IsOnline01"),  
     L("IsOnline02"),  
     L("IsOnline03"),  
     L("IsOnline04"),  
     L("IsOnline05"),  
     L("IsOnline06"),  
     L("IsOnline07"),  
     L("IsOnline08"),  
     L("IsOnline09"),  
     L("IsOnline10"),  
     L("IsOnline11"),  
     L("IsOnline12"),  
     L("IsOnline13"),  
     L("IsOnline14"),  
     L("IsOnline15"),  
     L("IsOnline16"),  
     L("IsOnline17"),  
     L("IsOnline18"),  
     L("IsOnline19"),  
     L("IsOnline20"),  
     L("LastModificationTime"),  
     L("CreationTime")  
                        );
         AddObjects(sheet,2,planDetailListDtos,
            
      _ => _.PlanId,   
       
      _ => _.SeatPositionId,   
       
      _ => _.SeatID,   
       
      _ => _.SeatSeq,   
       
      _ => _.IsOnline01,   
       
      _ => _.IsOnline02,   
       
      _ => _.IsOnline03,   
       
      _ => _.IsOnline04,   
       
      _ => _.IsOnline05,   
       
      _ => _.IsOnline06,   
       
      _ => _.IsOnline07,   
       
      _ => _.IsOnline08,   
       
      _ => _.IsOnline09,   
       
      _ => _.IsOnline10,   
       
      _ => _.IsOnline11,   
       
      _ => _.IsOnline12,   
       
      _ => _.IsOnline13,   
       
      _ => _.IsOnline14,   
       
      _ => _.IsOnline15,   
       
      _ => _.IsOnline16,   
       
      _ => _.IsOnline17,   
       
      _ => _.IsOnline18,   
       
      _ => _.IsOnline19,   
       
      _ => _.IsOnline20,   
       
 _ =>_timeZoneConverter.Convert( _.LastModificationTime,_abpSession.TenantId, _abpSession.GetUserId()),          
 _ =>_timeZoneConverter.Convert( _.CreationTime,_abpSession.TenantId, _abpSession.GetUserId())   
);
                    //写个时间转换的吧
          //var creationTimeColumn = sheet.Column(10);
                    //creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

        for (var i = 1; i <= 26; i++)
                    {
                        sheet.Column(i).AutoFit();
                    }       

});
   return file;

}


 

 
  

    }
    }
